import request from "@/utils/request";
import type { SysMenuDTO, SysMenuFiltDTO, SysMenuVO } from "./sysMenuType";
import type { IdDTO } from "../type/baseType";

enum URL {
    URL_MENU_BASE = '/menu',
    URL_MENU_ALL_TREE = URL_MENU_BASE + '/all/tree'
}

/**
 * 增加Menu
 * @param sysMenuDTO
 * @returns 
 */
export const addMenu = (sysMenuDTO: SysMenuDTO):
    Promise<undefined> =>
    request.post(URL.URL_MENU_BASE, sysMenuDTO)

/**
 * 删除Menu
 * @param id
 * @returns 
 */
export const deleteMenu = (id: IdDTO):
    Promise<undefined> =>
    request.delete(`${URL.URL_MENU_BASE}/${id.id}`)

/**
 * 修改Menu
 * @param id
 * @param sysMenuDTO
 * @returns 
 */
export const updateMenu = (id: IdDTO, sysMenuDTO: SysMenuDTO):
    Promise<undefined> =>
    request.put(`${URL.URL_MENU_BASE}/${id.id}`, sysMenuDTO)

/**
 * 查询当前登录用户可访问的所有Menu的树形结构
 * @param sysMenuFiltDTO
 * @returns 
 */
export const queryMenuAllTree = (sysMenuFiltDTO?: SysMenuFiltDTO):
    Promise<SysMenuVO[]> =>
    request.get(URL.URL_MENU_ALL_TREE, {
        params: sysMenuFiltDTO
    })